<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>Heat Meter Data Management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- JS通用工具 -->
	<jsp:include page="/resources/resource-refer/common-validator-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- EasyUI资源 -->
	<jsp:include page="/resources/resource-refer/component-easyui-reference.jsp" />
	<!-- 表单校验 -->
	<jsp:include page="/resources/resource-refer/component-validform-reference.jsp" />
	<!-- 用户访问菜单路径 -->
	<jsp:include page="/resources/usertrace/common-uservisit-reference.jsp" />
  </head>
  <script type="text/javascript">
  	function formVerify() {
  		var verify = true;
  		//抄表时间
  		var recordTime = $("input[name='recordTime']").val();
  		if(!isChinaDateTime($.trim(recordTime))) { 
  			$("span#span_recordTime").empty().append("<img src='"+path+"beshs/images/wrong.gif' />");
  			return false;
  		} else {
  			$("span#span_recordTime").empty().append("<img src='"+path+"beshs/images/right.gif' />");
  		}
  		return verify;
  	}
  
  	function submitForm() {
  		var meterDataUID = "<s:property value='meterDataUID' />";
  		//表单校验
  		var verify = formVerify();
  		if(!verify) return;
  		//表单信息
  		var heatMeterUID = $("select[name='heatMeterUID']").val(); //热量表ID
  		//累计热量
  		var sumHeat = $("input[name='sumHeat']").val();
  		var sumHeatUnit = $("select[name='meterData.sumHeatUnit']").val();
  		//累计流量
  		var sumFlow = $("input[name='sumFlow']").val();
  		//抄表时间
  		var recordTime = $("input[name='recordTime']").val();
  		//瞬时功率
  		var instantPower = $("input[name='instantPower']").val();
  		//瞬时流量
  		var instantFlow = $("input[name='instantFlow']").val();
  		//供水温度
  		var supplyTemperature = $("input[name='supplyTemperature']").val();
  		//回水温度
  		var backTemperature = $("input[name='backTemperature']").val();
  		//供回水温差
  		var temperatureDiff = $("input[name='temperatureDiff']").val();
  		//累计运行时间
  		var runHours = $("input[name='runHours']").val();
  		//累计出错时间
  		var wrongHours = $("input[name='wrongHours']").val();
  		//热表系统时间
  		var sysHours = $("input[name='sysHours']").val();
  		//故障信息
  		var wrongInfo = $("textarea[name='wrongInfo']").val();
  		//备注
  		var remark = $("textarea[name='remark']").val();
  		$.getJSON(path+"beshs/heatMeterDataGatherActionJson!saveOrUpdateMeterData.do?date="+new Date(), {
  			"heatMeterUID": heatMeterUID, //热量表ID
  			"meterData.id": meterDataUID,
  			"meterData.sumHeat": sumHeat,
  			"meterData.sumHeatUnit": sumHeatUnit,
  			"meterData.sumFlow": sumFlow,
  			"meterData.sumFlowUnit": 1,
  			"meterData.recordTime": recordTime,
  			"meterData.instantPower": instantPower,
  			"meterData.heatPowerUnit": 2,
  			"meterData.instantFlow": instantFlow,
  			"meterData.instantFlowUnit": 1,
  			"meterData.supplyTemperature": supplyTemperature,
  			"meterData.backTemperature": backTemperature,
  			"meterData.temperatureDiff": temperatureDiff,
  			"meterData.runHours": runHours,
  			"meterData.wrongHours": wrongHours,
  			"meterData.sysHours": sysHours,
  			"meterData.wrongInfo": $.trim(wrongInfo),
  			"meterData.remark": $.trim(remark)
  		});
  	}
  	
  	$(function(){
		$("form[name='heatMeterDataForm']").Validform({
			btnSubmit: "input[name='submit']",
			btnReset: "input[name='reset']",
			tiptype: function(msg, o, cssctl){
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
					var objtip=o.obj.siblings(".Validform_checktip");
					cssctl(objtip,o.type);
					objtip.text(msg);
				} else {
					var objtip=o.obj.find("#msgdemo");
					cssctl(objtip,o.type);
					objtip.text(msg);
				}
			},
			postonce: true, //开启二次提交防御，在数据成功提交后，表单将不能再继续提交
			showAllError: true, //提交表单时所有错误提示信息都会显示
			ajaxPost:true,
			callback: function(data){
	  			if(data.success) {
	  				Dialog.alert("Operation success！", function() {
	  					var index = parent.layer.getFrameIndex(window.name)
						parent.window.frames["c_content_content"].location = path + "beshs/heatMeterDataGatherAction!queryMeterDataPage.do?date"+new Date();
	  					parent.layer.close(index);
	  				});
	  			} else {
	  				Dialog.alert(data.msg);
	  			}
	  		},
			beforeSubmit: function(curform) { //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象
				var additionalVerify = formVerify();
				if(additionalVerify) {
					submitForm();
				}
				return true; //这里明确return false的话表单将不会提交
			}
		});
  	});
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#" name="heatMeterDataForm"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
          			<th>Project：</th>
          			<td>
          				<s:select name="projectUID" list="projectList" listKey="id" listValue="projectName" headerKey="" headerValue="Please select" cssClass="s_sel"
          					datatype="*" nullmsg="Please select the project！" errormsg="Please select the project！"></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip"></div></td>
            		<th>District：</th>
          			<td>
          				<script type="text/javascript">
          					function reloadCommunitys(projectUID, communityUID) {
          						$("select[name='communityUID']").children("option").slice(1).remove();
          						if(projectUID!=null && projectUID!="") {
		        					$.getJSON(path+"beshs/communityActionJson!queryCommunitysByBelongs.do?date="+new Date(), {
		        						projectUID: projectUID
		        					}, function(data) {
		        						for(var index=0; index<data.length; index++) {
		        							if(communityUID!=null && communityUID!="" && communityUID==data[index].id) {
		        								$("select[name='communityUID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].communityName+"</option>");
		        							} else {
		        								$("select[name='communityUID']").append("<option value='"+data[index].id+"'>"+data[index].communityName+"</option>");
		        							}
		        						}
		        					});
		        				} 
          					}	
          				
	          				$("select[name='projectUID']").change(function(){
								var projectUID = $(this).val();
	  							var communityUID = $("select[name='communityUID']").val();
	  							reloadCommunitys(projectUID, communityUID);
	  						});
          				</script>
          				<s:select name="communityUID" list="communityList" listKey="id" listValue="communityName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
          			</td>
        		</tr>
        		<tr>
        			<th>Shared Area：</th>
          			<td>
          				<script type="text/javascript">
	          				function reloadShareAreas(projectUID, communityUID, shareAreaUID) {
	      						$("select[name='shareAreaUID']").children("option").slice(1).remove();
	      						if((projectUID!=null && projectUID!="") 
          								|| (communityUID!=null && communityUID!="")) {
		        					$.getJSON(path+"beshs/shareAreaActionJson!queryShareAreasByBelongings.do?date="+new Date(), {
		        						projectUID: projectUID,
		        						communityUID: communityUID
		        					}, function(data) {
		        						for(var index=0; index<data.length; index++) {
		        							if(shareAreaUID!=null && shareAreaUID!="" && shareAreaUID==data[index].id) {
		        								$("select[name='shareAreaUID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].areaName+"</option>");
		        							} else {
		        								$("select[name='shareAreaUID']").append("<option value='"+data[index].id+"'>"+data[index].areaName+"</option>");
		        							}
		        						}
		        					});
		        				} 
	      					}
	      				
	          				$(function(){
	      						$("select[name='projectUID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='communityUID']").val();
			        				var shareAreaUID = $("select[name='shareAreaUID']").val();
			        				reloadShareAreas(projectUID, communityUID, shareAreaUID);
			        			});
	      						
	      						$("select[name='communityUID']").change(function(){
									var communityUID = $(this).val();
	      							var projectUID = $("select[name='projectUID']").val();
	      							var shareAreaUID = $("select[name='shareAreaUID']").val();
	      							reloadShareAreas(projectUID, communityUID, shareAreaUID);
	      						});
	      					});
          				</script>
          				<s:select name="shareAreaUID" list="shareAreaList" listKey="id" listValue="areaName" headerKey="" headerValue="Please select" cssClass="s_sel"></s:select>
          			</td>
          			<th>Heat Meter No.：</th>
          			<td>
          				<script type="text/javascript">
          					function reloadHeatMeters(projectUID, communityUID, shareAreaUID, heatMeterUID) {
          						$("select[name='heatMeterUID']").children("option").slice(1).remove();
          						$.getJSON(path+"beshs/heatMeterActionJson!queryMetersByBelongs.do?date="+new Date(), {
	        						projectUID: projectUID,
	        						communityUID: communityUID,
	        						shareAreaUID: shareAreaUID
	        					}, function(data) {
	        						for(var index=0; index<data.length; index++) {
	        							if(heatMeterUID!=null && heatMeterUID!="" && heatMeterUID==data[index].id) {
	        								$("select[name='heatMeterUID']").append("<option value='"+data[index].id+"' selected='selected'>"+data[index].meterNo+"</option>");
	        							} else {
	        								$("select[name='heatMeterUID']").append("<option value='"+data[index].id+"'>"+data[index].meterNo+"</option>");
	        							}
	        						}
	        					});
          					}
          					
          					$(function() {
          						$("select[name='projectUID']").change(function(){
			        				var projectUID = $(this).val();
			        				var communityUID = $("select[name='communityUID']").val();
			        				var shareAreaUID = $("select[name='shareAreaUID']").val();
			        				var heatMeterUID = $("select[name='heatMeterUID']").val();
			        				reloadHeatMeters(projectUID, communityUID, shareAreaUID, heatMeterUID);
			        			});
	      						
	      						$("select[name='communityUID']").change(function(){
									var communityUID = $(this).val();
	      							var projectUID = $("select[name='projectUID']").val();
	      							var shareAreaUID = $("select[name='shareAreaUID']").val();
	      							var heatMeterUID = $("select[name='heatMeterUID']").val();
	      							reloadHeatMeters(projectUID, communityUID, shareAreaUID, heatMeterUID);
	      						});
	      						
	      						$("select[name='shareAreaUID']").change(function(){
									var shareAreaUID = $(this).val();
	      							var projectUID = $("select[name='projectUID']").val();
	      							var communityUID = $("select[name='communityUID']").val();
	      							var heatMeterUID = $("select[name='heatMeterUID']").val();
	      							reloadHeatMeters(projectUID, communityUID, shareAreaUID, heatMeterUID);
	      						});
          					});
          				</script>
          				<s:select name="heatMeterUID" list="heatMeterList" listKey="id" listValue="meterNo" headerKey="" headerValue="Please select" cssClass="s_sel"
          					datatype="*" nullmsg="Please select heat meter no.！" errormsg="Please select heat meter no.！"></s:select>
          				&nbsp;<span style="color:#FF0000;">*</span>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th colspan="2">Accumulated Heat：</th>
          			<td colspan="2">
          				<input name="sumHeat" type="text" class="s_input" value="<s:property value='meterData.sumHeat' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" sucmsg="Accumulated Heat Verification Passed！" nullmsg="Please enter accumulated heat！" errormsg="Please enter integral or float type value！"/>
            			<s:select name="meterData.sumHeatUnit" list="#{'1':'MWh', '2':'kWh', '3':'Gj'}" cssClass="s_sel" ></s:select>
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Please enter integral or float type value！</div></td>
        		</tr>
        		<tr>
        			<th>Meter Reading Time：</th>
        			<td>
        			<input id="recordTime" name="recordTime" class="Wdate" value="<s:date name='meterData.recordTime' format='yyyy-MM-dd HH:mm:ss' nice='false' />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
        				
<!--         				<input name="recordTime" id="recordTime" alt="Meter Reading Time"  class="easyui-datetimebox" type="text"  -->
<%--         						value="<s:date name='meterData.recordTime' format='yyyy-MM-dd HH:mm:ss' nice='false' />" readOnly/> --%>
        				&nbsp;<span style="color:#FF0000;" id="span_recordTime">*</span>
        				<div class="Validform_checktip">Please enter date and time in correct format such as--2014-07-30 15:52:00！</div></td>
        			<th>Accumulated Flow：</th>
        			<td>
        				<input name="sumFlow" type="text" class="s_input" value="<s:property value='meterData.sumFlow' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;m&sup3;<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Instantaneous Power：</th>
        			<td>
        				<input name="instantPower" type="text" class="s_input" value="<s:property value='meterData.instantPower' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;kW<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        			<th>Instantaneous Flow：</th>
        			<td>
        				<input name="instantFlow" type="text" class="s_input" value="<s:property value='meterData.instantFlow' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;m&sup3;/h<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Temperature of Supply Water：</th>
        			<td>
        				<input name="supplyTemperature" type="text" class="s_input" value="<s:property value='meterData.supplyTemperature' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;&#8451;<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        			<th>Temperature of Return Water：</th>
        			<td>
        				<input name="backTemperature" type="text" class="s_input" value="<s:property value='meterData.backTemperature' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;&#8451;<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Temperature Difference between Supply Water and Return Water：</th>
        			<td>
        				<input name="temperatureDiff" type="text" class="s_input" value="<s:property value='meterData.temperatureDiff' />" 
        					datatype="n1-10|/^-?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;&#8451;<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        			<th>Accumulated Operating Time Accuracy：</th>
        			<td>
        				<input name="runHours" type="text" class="s_input" value="<s:property value='meterData.runHours' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;h<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Accumulated Error Time：</th>
        			<td>
        				<input name="wrongHours" type="text" class="s_input" value="<s:property value='meterData.wrongHours' />" 
        					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！"/>
        				&nbsp;h<span style="color:#FF0000;"></span>
        				<div class="Validform_checktip"></div></td>
        			<th>System Time of Heat Meter：</th>
        			<td>
        			<input id="sysHours" name="sysHours" class="Wdate" value="<s:date name='meterData.sysHours' format='yyyy-MM-dd HH:mm:ss' nice='false' />" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',readOnly:true})" />
        				
<!--         				<input name="sysHours" id="sysHours" alt="System Time of Heat Meter"  class="easyui-datetimebox" type="text"  -->
<%--         						value="<s:date name='meterData.sysHours' format='yyyy-MM-dd HH:mm:ss' nice='false' />" readOnly/> --%>
        				&nbsp;<span style="color:#FF0000;" id="span_sysHours"></span>
        				<div class="Validform_checktip">Please enter date and time in correct format such as--2014-07-30 15:52:00！</div></td>
        		</tr>
        		<tr>
        			<th>Fault Information：</th>
          			<td colspan="3">
          				<textarea name="wrongInfo" cols="45" rows="3"  onfocus="this.value=''"  onblur="if(this.value=='')this.value='no error'"
          					datatype="*1-50" ignore="ignore" errormsg="请填写有效内容，控制在1-50个字符！">
          					<s:property value='meterData.wrongInfo' /></textarea>
          				&nbsp;<span style="color:#FF0000;">*</span>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
        			<th>Remark：</th>
          			<td colspan="3">
          				<textarea name="remark" cols="45" rows="3"
          					datatype="*1-200" ignore="ignore" errormsg="Invalid input!  please input valid content ,no more than 200pcs character">
          					<s:property value='meterData.remark' /></textarea>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="button" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
